<?php
namespace app\api\model;

use think\Model;
use think\Request;
use think\Db;
class Form extends Model
{
    protected $tableName;
    //构造方法，实例化表名
    public function __construct($tableName = ''){
        $this->tableName = $tableName;
    }
    public $form_list=array(
        "1"=>"订单生成,等待用户付款",
        "12"=>"买家取消订单，订单结束",
        "2"=>"买家已付款,文件待上传",
        "3"=>"卖家已上传合同，等待下载",
        "4"=>"合同待确认",
        "5"=>"已确认合同，待上传快递单号",
        "6"=>"已上传快递单号，待平台确认收货并邮寄",
        "7"=>"待接收合同",
        "8"=>"等待买家评价",
        "9"=>"买家已评价，订单完成",
        "10"=>"申请退款",
        "11"=>"退款完成，订单结束"
    );
    public function getForm()
    {
        return $this->form_list;
    }
    public $selle_list=array(
        "1"=>"订单生成,等待用户付款",
        "14"=>"买家逾期未付款，取消订单，订单结束",
        "2"=>"文件待上传",
		"3"=>"文件待下载",
        "4"=>"买家已下载,可重新上传新文件",
        "5"=>"待卖家上传快递号",
        "6"=>"待平台审核",
        "7"=>"待接收合同",
        "8"=>"待平台打款",
        "9"=>"待确认收款",
        "10"=>"待卖家评价",
        "11"=>"卖家已评价，订单完成",
        "12"=>"待退款",
        "13"=>"已退款"
    );
    public function getSeller()
    {
        return $this->selle_list;
    }
    public function rand_order(){
        mt_srand((double)microtime()*1000000*getmypid());
        $start=date('ymd');
        $mid=str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
        $last=substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 5);
        $order_num=$start.$mid.$last;
        return $order_num;
    }
    /* 订单列表
     *
     * $where:条件（带别名条件）
     * */
    public function order_list($type1,$type2,$type3,$where,$condition1,$condition2,$condition3,$fields,$order,$limit,$page){
        $data=Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->join($type3,$condition3,'left')
            ->where($where)
            ->order($order)
            ->limit($limit)
            ->page($page)->select();
        return $data;
    }
    /* 订单列表
     *
     * $where:条件（带别名条件）
     * */
    public function trading_list($type1,$type2,$type3,$type4,$where,$condition1,$condition2,$condition3,$condition4,$fields,$order,$limit,$page){
        $data=Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->join($type3,$condition3,'left')
            ->join($type4,$condition4,'left')
            ->where($where)
            ->order($order)
            ->limit($limit)
            ->page($page)->select();
        return $data;
    }
    public function order_group($type1,$type2,$type3,$where,$condition1,$condition2,$condition3,$fields,$group){
        $data=Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->join($type3,$condition3,'left')
            ->where($where)
            ->group($group)
            ->select();
        return $data;
    }
    /***服务訂單詳情**/
    public function order_details($type1,$type2,$type3,$where,$condition1,$condition2,$condition3,$fields){
        $data=Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->join($type3,$condition3,'left')
            ->where($where)
            ->find();
        return $data;
    }
    /***訂單詳情**/
    public function order_trading($type1,$type2,$type3,$type4,$where,$condition1,$condition2,$condition3,$condition4,$fields){
        $data=Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->join($type3,$condition3,'left')
            ->join($type4,$condition4,'left')
            ->where($where)
            ->find();
        return $data;
    }
    //修改状态
    public function edit_form($where,$data){
        return Db::name($this->tableName)->where($where)->update($data);
    }
    //修改状态
    public function add_form($data){
        return Db::name($this->tableName)->insert($data);
    }
    //获取全部符合条件列表
    public function form_list($where, $view = "*",$order,$limit){
        return $data = Db::name($this->tableName)->where($where)->field($view)->limit($limit)->order($order)->select();
    }

    public function service_list($type1,$type2,$where,$condition1,$condition2,$fields,$order,$limit,$page){
        $data=Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->where($where)
            ->order($order)
            ->limit($limit)
            ->page($page)->select();
        return $data;
    }
    public function service_group($type1,$type2,$where,$condition1,$condition2,$fields,$group){
        $data=Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->where($where)
            ->group($group)
            ->select();
        return $data;
    }

}
